<h1><?php echo $this->pageTitle = __('List Campaigns', true); ?></h1>
<div class="index">
	<div class="filter">
		<?php 
			echo $html->link(__('Show', true), 'javascript:void(0);', array('class'=>'popup_link', 'id'=>'popup_link_filter'));
			echo ' '.__('all', true).' ';
			if (isset($params['active']) && $params['active']!=='NULL') echo $html->link(array_search($params['active'], array(__('active', true)=>1, __('inactive', true)=>0)), 'javascript:void(0);', array('class'=>'popup_link', 'id'=>'popup_link_active')).' ';
			__('campaigns');
			
			if (isset($params['priority']) && $params['priority']!=='NULL') echo ' '.__('with', true).' '.$html->link(array_search($params['priority'], array('low'=>1, 'medium'=>2, 'high'=>3)), 'javascript:void(0);', array('class'=>'popup_link', 'id'=>'popup_link_priority')).' '.__('priority', true);
			echo '.';
		?>
	</div>
	<div class="popup popup_link_filter" style="display:none;">
		<ul>
			<li><?php echo $html->link('Active', am($params, array('active'=>1))); ?></li>
			<li><?php echo $html->link('Inactive', am($params, array('active'=>0))); ?></li>
			<li><hr /></li>
		</ul><ul id="PopupTreePriority">
			<li><b><?php __('Priority'); ?></b>
				<ul>
					<li><?php echo $html->link('Low', am($params, array('priority'=>1))); ?></li>
					<li><?php echo $html->link('Normal', am($params, array('priority'=>2))); ?></li>
					<li><?php echo $html->link('High', am($params, array('priority'=>3))); ?></li>
				</ul>
			</li>
		</ul><ul>
			<li><hr /></li>
			<li><?php echo $html->link('All', array('filter'=>'all')); ?></li>
		</ul>
	</div>
	<div class="popup popup_link_active" style="display:none;">
		<ul>
			<li><?php echo $html->link('Active', am($params, array('active'=>1))); ?></li>
			<li><?php echo $html->link('Inactive', am($params, array('active'=>0))); ?></li>
			<li><hr /></li>
			<li><?php echo $html->link('All', am($params, array('active'=>'NULL'))); ?></li>
		</ul>
	</div>
	<div class="popup popup_link_priority" style="display:none;">
		<ul>
			<li><?php echo $html->link('Low', am($params, array('priority'=>1))); ?></li>
			<li><?php echo $html->link('Normal', am($params, array('priority'=>2))); ?></li>
			<li><?php echo $html->link('High', am($params, array('priority'=>3))); ?></li>
			<li><hr /></li>
			<li><?php echo $html->link('All', am($params, array('priority'=>'NULL'))); ?></li>
		</ul>
	</div>
	<br />
	<?php echo $html->link(__('Create a new Campaign', true), array('action'=>'admin_add')); ?>
	<table cellpadding="0" cellspacing="0">
	<tr>
		<th><?php echo $paginator->sort(__('Campaign', true), 'title');?><br /><span class="sub"><?php __('Ad'); ?></span></th>
		<th align="center"><?php echo $paginator->sort(__('Priority', true), 'priority');?><br /><span class="sub"><?php __('Size'); ?></span></th>
		<th align="center"><?php echo $paginator->sort(__('Click Count', true), 'clicks');?></th>
		<th align="center"><?php echo $paginator->sort(__('Display Count', true), 'views');?></th>
		<th align="center"><?php echo __('CTR', true).' [%]';?></th>
		<?php if (!@$stats) { ?>
		<th align="center"><?php __('Actions');?></th>
		<?php } ?>
	</tr>
<?php
	$i = 0; 
	$priority = array(1=>__('low', true), 2=>__('medium', true), 3=>__('high', true));
	$banner_kinds = array('I' => __('image', true), 'F' => __('flash', true), 'P' => __('plain', true), 'H' => __('html', true));
	
	foreach ($campaigns as $campaign) {
		echo '<tr id="row_'.$campaign['Campaign']['id'].'"'.(($i++ % 2 == 0)?' class="altrow"':'').'>';
		
		echo '<td'.ife($campaign['Campaign']['active']==0, ' class="deleted"', '').'>';
		if (!@$stats) {
			echo '<b>'.h($campaign['Campaign']['title']).'</b>';
		} else {
			echo $html->link($campaign['Campaign']['title'], array('plugin'=>'lilads', 'controller'=>'actions', 'action'=>'admin_daily', 'campaign_id'=>$campaign['Campaign']['id']));	
		}
		echo '</td>';
		
		echo '<td align="center"'.ife($campaign['Campaign']['active']==0, ' class="deleted"', '').'><b>'.h($priority[$campaign['Campaign']['priority']]).'</b></td>';
		echo '<td align="center"'.ife($campaign['Campaign']['active']==0, ' class="deleted"', '').'><b>'.h($campaign['Campaign']['clicks']).'</b></td>';
		echo '<td align="center"'.ife($campaign['Campaign']['active']==0, ' class="deleted"', '').'><b>'.h($campaign['Campaign']['views']).'</b></td>';
		echo '<td align="center"'.ife($campaign['Campaign']['active']==0, ' class="deleted"', '').'><b>'.sprintf('%.2f', ($campaign['Campaign']['views']>0)?($campaign['Campaign']['clicks']/$campaign['Campaign']['views']*100):0).'</b></td>';
		
		if (!@$stats) {
			echo '<td align="center">';
			if ($campaign['Campaign']['active']==0) {
				echo $html->link(__('Activate', true), array('action'=>'admin_activate', $campaign['Campaign']['id']));
			} else {
				echo $html->link(__('Update', true), array('action'=>'admin_refresh', $campaign['Campaign']['id']));
				//echo '<br />';
				echo $html->link(__('Edit', true), array('action'=>'admin_edit', $campaign['Campaign']['id']));
				echo $html->link(__('Delete', true), array('action'=>'admin_delete', $campaign['Campaign']['id']));
				//echo '<br />';
				echo $html->link(__('Add a new Ad', true), array('plugin'=>'lilads', 'controller'=>'banners', 'action'=>'admin_add', 'campaign'=>$campaign['Campaign']['id']));
			}
			echo '</td>';
			echo '</tr>';
		}
		
		if ($campaign['Campaign']['active']==1) {
			foreach ($campaign['Banner'] as $banner) {
				echo '<tr'.(($i % 2 == 0)?' class="altrow"':'').'>';
				echo '<td class="sub">'.'['.$banner_kinds[$banner['kind']].'] ';
				if (!@$stats) {
					echo h($banner['title']);
				} else {
					echo $html->link($banner['title'], array('plugin'=>'lilads', 'controller'=>'actions', 'action'=>'admin_daily', 'campaign_id'=>$campaign['Campaign']['id'], 'banner_id'=>$banner['id']));
				}
				echo '</td>';
				echo '<td align="center">'.((!empty($banner['width']))?($banner['width'].'x'.$banner['height'].'px'):'N/A').'</td>';
				echo '<td></td>';
				echo '<td></td>';
				echo '<td></td>';
				if (!@$stats) {
					echo '<td align="center">';
						echo $html->link(__('Edit', true), array('plugin'=>'lilads', 'controller'=>'banners', 'action'=>'admin_edit', $banner['id']));
						echo $html->link(__('Delete', true), array('plugin'=>'lilads', 'controller'=>'banners', 'action'=>'admin_delete', $banner['id']));
					echo '</td>';
				}	
				echo '</tr>';
			}
		}
	}
?>
	</table>
	<div class="paging">
		<?php 
			echo $paginator->prev('<< ' . __('previous', true), array(), null, array('class'=>'disabled'));
			echo ' | ';
	 		echo $paginator->numbers();
			echo  $paginator->next(__('next', true) .' >>', array(), null, array('class'=>'disabled'));
		?>
	</div>
</div>
